Home:ALL Converter>Why is the result of `a * b` and `a *= b` for floating point numbers different

Why is the result of `a * b` and `a *= b` for floating point numbers different

Ask Time:2020-12-16T18:43:10         Author:t.niese

Json Formatter

I borrowed this code from a question that was marked as duplicate and then deleted 1, but because I was not able to find an exact duplicate to it I would like to create a new question for that.

I'm aware of the problems with floating-point arithmetic (Is floating point math broken?), but this special case is still interesting.

The following two snippets look seemingly equal:

let a = 860.42065
a *= 1/860.42065
console.log(a);

Author:t.niese,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/65321687/why-is-the-result-of-a-b-and-a-b-for-floating-point-numbers-different
yy